package com.wcpdoc.exam.core.service.impl;

import com.wcpdoc.base.dao.DictDao;
import com.wcpdoc.base.entity.Dict;
import com.wcpdoc.core.dao.BaseDao;
import com.wcpdoc.core.exception.MyException;
import com.wcpdoc.core.service.impl.BaseServiceImp;
import com.wcpdoc.core.util.ValidateUtil;
import com.wcpdoc.exam.core.dao.MyAbnormalDao;
import com.wcpdoc.exam.core.entity.MyAbnormal;
import com.wcpdoc.exam.core.service.MyAbnormalService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 收藏服务层实现
 * 
 */
@Service
public class MyAbnormalServiceImpl extends BaseServiceImp<MyAbnormal> implements MyAbnormalService {
	@Resource
	private MyAbnormalDao myAbnormalDao;
	@Resource
	private DictDao dictDao;
	@Override
	@Resource(name = "myAbnormalDaoImpl")
	public void setDao(BaseDao<MyAbnormal> dao) {
		super.dao = dao;
	}

	@Override
	public void addAbnormal(MyAbnormal myAbnormal) {
		// 数据校验
		paramValid(myAbnormal);
		List<Dict> lsDict = dictDao.getListByIndex("ABNORMAL_TYPE");
		for (Dict item:lsDict){
			if(Integer.parseInt(item.getDictKey())==myAbnormal.getAbnormalTypeId()){
				myAbnormal.setAbnormalTypeName(item.getDictValue());
			}
		}
		add(myAbnormal);
	}

	@Override
	public void delAbnormal(MyAbnormal myAbnormal) {
		// 数据校验

	}

	@Override
	public List<Dict> getAbnormalTypeList() {
		return dictDao.getListByIndex("FEEDBACK_TEST");
	}

	@Override
	public List<Dict> getAbnormalSysTypeList() {
		return dictDao.getListByIndex("ABNORMAL_TYPE");
	}
	
	private void paramValid(MyAbnormal myAbnormal) {
		if (!ValidateUtil.isValid(myAbnormal.getAbnormalTypeId())) {
			throw new MyException("参数错误：AbnormalTypeId");
		}
		if (!ValidateUtil.isValid(myAbnormal.getUserId())) {
			throw new MyException("参数错误：userId");
		}
		if (!ValidateUtil.isValid(myAbnormal.getAbnormalContent())) {
			throw new MyException("参数错误：AbnormalContent");
		}
	}
}
